package com.hjc.service.user;

import com.hjc.dao.user.UserMapper;
import com.hjc.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户业务类，实现读User的业务管理
 */

@Service("userService")
public class UserServiceImpl implements  UserService {
    @Autowired
    private UserMapper userMapper;  //声明UserMapper接口引用

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findUsersWithConditions(User user) {
        try {
            return userMapper.getUserList(user);    //调用DAO方法实现查询
        }catch (RuntimeException e){
            e.printStackTrace();
            throw  e;
        }

    }

    @Override
    public boolean addNewUser(User user) {
        boolean result = false;
        try {
            if(userMapper.add(user) ==1)
                result = true;
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int xiugai(User user) {
        return userMapper.xg(user);
    }

    @Override
    public int xiugaipass(User user) {
        return userMapper.xgpass(user);
    }

    @Override
    public int deleleinfo(User user) {
        return userMapper.delete(user);
    }


    public  UserMapper getUserMapper(){

        return  userMapper;
    }
    public void setUserMapper(UserMapper userMapper){

        this.userMapper = userMapper;
    }

}
